package deng.hibernate.test.storeproc;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.*;

@Entity
@Table(name="t_simple")

//@NamedNativeQuery(
//	name="countSimple", 
//	query="{? = call count_simple() }",
//	resultClass=java.lang.Integer.class,
//	hints={@QueryHint(name="org.hibernate.callable", value="true")}
//)

@SqlResultSetMappings({
	@SqlResultSetMapping(name="countSimple2Mapping", columns=@ColumnResult(name="count")),
	@SqlResultSetMapping(name="countSimple3Mapping", columns=@ColumnResult(name="count"))
})
@org.hibernate.annotations.NamedNativeQueries({
	@org.hibernate.annotations.NamedNativeQuery(
		name="countSimple2", 
		query="call count_simple2()",
		callable=true,
		resultSetMapping = "countSimple2Mapping"
	),
	@org.hibernate.annotations.NamedNativeQuery(
		name="countSimple3", 
		query="select count(*) as count from t_simple",
		callable=true,
		resultSetMapping = "countSimple3Mapping"
	)
})

public class Simple {

	@Id
	@GeneratedValue
	private Long id;
	public Long getId() {
		return id;
	}
	
	private String name;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	private Double rate;
	public Double getRate() {
		return rate;
	}
	public void setRate(Double rate) {
		this.rate = rate;
	}
	
	private BigDecimal price;
	public BigDecimal getPrice() {
		return price;
	}
	public void setPrice(BigDecimal price) {
		this.price = price;
	}
	
	@Column(name="count_num")
	private int count;
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	
	@Column(name="created_date")
	@Temporal(TemporalType.TIMESTAMP)
	private Date createdDate;
	public Date getCreatedDate() {
		return createdDate;
	}
	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}
	
	@Override
	public String toString() {
		return getClass().getName() + "[id=" + id + ",name=" + name + " ...]";
	}
	
	public void sample() {
		name = "foo";
		rate = 0.1;
		price = new BigDecimal(99.00);
		count = 8;
		createdDate = new Date();
		
	}
}
